<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <meta name="referrer" content="no-referrer" />
    <meta
      name="description"
      content="汇融名企是面向全国商家服务的大型互联网平台，为商家提供流量扶持，引导品牌曝光；为消费者提供风云榜单，招商加盟，引导实现消费，达成合作，上汇融名企实现共赢。"
    />
    <title>名企榜-汇融名企</title>
    <link rel="stylesheet" href="./css/common.css" />
    <link rel="stylesheet" href="./css/ranking.css" />
    <link rel="stylesheet" href="./css/rankingPage.css" />
  </head>
  <body>
    <!-- <div id="header-page"></div> -->
    <!--#include virtual="/header.html" -->
    <div class="content-wrapper">
      <div class="ranking-top">
        <div class="ranking-search">
          <img
            class="ranking-search-icon"
            src="./image/icon/ranking_search.png"
            alt=""
          />
          <input
            id="ranking-search"
            class="ranking-search-input"
            placeholder="大家都在搜：建材最新排行榜单"
            type="text"
          />
          <div class="ranking-search-button" id="ranking-search-button">
            搜索
          </div>
        </div>
      </div>
      <div class="content">
        <div class="investment-wrapper" id="investment-wrapper">
          <div class="not-found" id="top-not-found">未找到结果</div>
          <!-- <div class="investment">
  <div class="investment-img">
    <img class="investment-img" src="" alt="" />
  </div>
  <div class="investment-text need-text-overflow">石家庄欧力健身房河北石家庄市裕华区天...</div>
</div> -->
        </div>
        <div class="title" style="margin-top: 0;">
          <div style="position: relative;">
            <img src="./image/picture/rankingPage_title_latest.png" alt="" />
            <div class="title-more">MORE <span>></span></div>
          </div>
          <div class="title-divider-wrapper">
            <div class="title-divider-colorbar"></div>
            <div class="title-divider"></div>
          </div>
        </div>
        <div class="ranking-wrapper" id="ranking-wrapper">
          <div class="not-found" id="bottom-not-found">未找到结果</div>
        </div>
      </div>
    </div>
    <!-- <div id="footer-page"></div>  -->
    <!--#include virtual="/footer.html" -->
    <script src="./js/jquery-1.11.0.min.js"></script>
    <script src="./js/jquery.my-message.1.1.js"></script>
    <script src="./js/utils.js"></script>
    <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
    <script src="./js/ranking.js"></script>
    <script src="./js/api.js"></script>
    <script type="text/javascript">
      $(function () {
        // $('#header-page').load('header.html')
        // $('#footer-page').load('footer.html')
        if (sessionStorage.getItem('city_name')) {
          $('#ranking-search').attr(
            'placeholder',
            '大家都在搜：' +
              sessionStorage.getItem('city_name') +
              '建材最新排行榜单'
          )
        }
        $('.title-more').click(function () {
          sessionStorage.removeItem('title')
          go('rankingList.html')
        })
        // var timer = ''
        $('#ranking-search').keydown(function (e) {
          var title = $('#ranking-search').val()
          if (e.keyCode == 13 && title) {
            sessionStorage.setItem('title', title)
            go('rankingList.html')
          }
          // if (timer) {
          //   return false
          // }
          // var that = this
          // var title = $(that).val()
          // if (event.keyCode == 13 && title) {
          //   timer = setTimeout(function() {
          //     go('rankingList.html')
          //     timer = ''
          //   }, 200)
          // }
        })
        $('#ranking-search-button').click(function () {
          var title = $('#ranking-search').val()
          if (title) {
            sessionStorage.setItem('title', title)
            go('rankingList.html')
          }
        })
        getData()
      })
      function init(data) {
        var investment = [{}, {}, {}, {}, {}, {}, {}, {}]
        if (data.list.length > 0) {
          $('#top-not-found').hide()
          initInvestment(data.list, 4, $('#investment-wrapper'))
        } else {
          $('#top-not-found').show()
        }
        if (data.ranking.length > 0) {
          $('#bottom-not-found').hide()
          initRanking(data.ranking, 4, $('#ranking-wrapper'))
        } else {
          $('#bottom-not-found').show()
        }
      }
      function initInvestment(data, num, parent) {
        var el = ''
        for (key in data) {
          var currentData = data[key]
          var flag = (+key + 1) % num
          var temp = [
            '<div class="investment" ' +
              (flag ? '' : 'style="margin-right:0;"') +
              '>',
            '  <div class="investment-img" id="' + currentData.id + '">',
            '    <img class="investment-img" src="' +
              (currentData.images.indexOf('http') > -1
                ? currentData.images
                : URL + currentData.images) +
              '" alt="" />',
            '  </div>',
            '  <div class="investment-text need-text-overflow" id="' +
              currentData.id +
              '">' +
              currentData.title +
              '</div>',
            '</div>',
          ].join('')
          el += temp
        }

        parent.append(el)
        $('.investment-img').click(handleClick)
        $('.investment-text').click(handleClick)
      }
      function getData(title) {
        $('.investment').remove()
        $('.ranking').remove()
        var params = {
          city_id: sessionStorage.getItem('city_id'),
        }
        title ? (params.title = title) : (params.title = '')
        var api = new ajax('GET', '/api/home/ranking', params)
        api.then(function (res) {
          init(JSON.parse(res).data)
        })
      }
      function handleClick() {
        var id = $(this).attr('id')
        go('rankingDetail.html?list_id=' + id)
      }
    </script>
  </body>
</html>
